// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Security;

public sealed partial class IndicesPrivileges
{
	/// <summary>
	/// <para>
	/// The document fields that the owners of the role have read access to.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("field_security")]
	public Elastic.Clients.Elasticsearch.Serverless.Security.FieldSecurity? FieldSecurity { get; set; }

	/// <summary>
	/// <para>
	/// A list of indices (or index name patterns) to which the permissions in this entry apply.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("names")]
	public ICollection<Elastic.Clients.Elasticsearch.Serverless.IndexName> Names { get; set; }

	/// <summary>
	/// <para>
	/// The index level privileges that owners of the role have on the specified indices.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("privileges")]
	public ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.IndexPrivilege> Privileges { get; set; }

	/// <summary>
	/// <para>
	/// A search query that defines the documents the owners of the role have access to. A document within the specified indices must match this query for it to be accessible by the owners of the role.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("query")]
	public object? Query { get; set; }
}

public sealed partial class IndicesPrivilegesDescriptor<TDocument> : SerializableDescriptor<IndicesPrivilegesDescriptor<TDocument>>
{
	internal IndicesPrivilegesDescriptor(Action<IndicesPrivilegesDescriptor<TDocument>> configure) => configure.Invoke(this);

	public IndicesPrivilegesDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Security.FieldSecurity? FieldSecurityValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Security.FieldSecurityDescriptor<TDocument> FieldSecurityDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Security.FieldSecurityDescriptor<TDocument>> FieldSecurityDescriptorAction { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.IndexName> NamesValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.IndexPrivilege> PrivilegesValue { get; set; }
	private object? QueryValue { get; set; }

	/// <summary>
	/// <para>
	/// The document fields that the owners of the role have read access to.
	/// </para>
	/// </summary>
	public IndicesPrivilegesDescriptor<TDocument> FieldSecurity(Elastic.Clients.Elasticsearch.Serverless.Security.FieldSecurity? fieldSecurity)
	{
		FieldSecurityDescriptor = null;
		FieldSecurityDescriptorAction = null;
		FieldSecurityValue = fieldSecurity;
		return Self;
	}

	public IndicesPrivilegesDescriptor<TDocument> FieldSecurity(Elastic.Clients.Elasticsearch.Serverless.Security.FieldSecurityDescriptor<TDocument> descriptor)
	{
		FieldSecurityValue = null;
		FieldSecurityDescriptorAction = null;
		FieldSecurityDescriptor = descriptor;
		return Self;
	}

	public IndicesPrivilegesDescriptor<TDocument> FieldSecurity(Action<Elastic.Clients.Elasticsearch.Serverless.Security.FieldSecurityDescriptor<TDocument>> configure)
	{
		FieldSecurityValue = null;
		FieldSecurityDescriptor = null;
		FieldSecurityDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A list of indices (or index name patterns) to which the permissions in this entry apply.
	/// </para>
	/// </summary>
	public IndicesPrivilegesDescriptor<TDocument> Names(ICollection<Elastic.Clients.Elasticsearch.Serverless.IndexName> names)
	{
		NamesValue = names;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The index level privileges that owners of the role have on the specified indices.
	/// </para>
	/// </summary>
	public IndicesPrivilegesDescriptor<TDocument> Privileges(ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.IndexPrivilege> privileges)
	{
		PrivilegesValue = privileges;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A search query that defines the documents the owners of the role have access to. A document within the specified indices must match this query for it to be accessible by the owners of the role.
	/// </para>
	/// </summary>
	public IndicesPrivilegesDescriptor<TDocument> Query(object? query)
	{
		QueryValue = query;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (FieldSecurityDescriptor is not null)
		{
			writer.WritePropertyName("field_security");
			JsonSerializer.Serialize(writer, FieldSecurityDescriptor, options);
		}
		else if (FieldSecurityDescriptorAction is not null)
		{
			writer.WritePropertyName("field_security");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Security.FieldSecurityDescriptor<TDocument>(FieldSecurityDescriptorAction), options);
		}
		else if (FieldSecurityValue is not null)
		{
			writer.WritePropertyName("field_security");
			JsonSerializer.Serialize(writer, FieldSecurityValue, options);
		}

		writer.WritePropertyName("names");
		JsonSerializer.Serialize(writer, NamesValue, options);
		writer.WritePropertyName("privileges");
		JsonSerializer.Serialize(writer, PrivilegesValue, options);
		if (QueryValue is not null)
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, QueryValue, options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class IndicesPrivilegesDescriptor : SerializableDescriptor<IndicesPrivilegesDescriptor>
{
	internal IndicesPrivilegesDescriptor(Action<IndicesPrivilegesDescriptor> configure) => configure.Invoke(this);

	public IndicesPrivilegesDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Security.FieldSecurity? FieldSecurityValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Security.FieldSecurityDescriptor FieldSecurityDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Security.FieldSecurityDescriptor> FieldSecurityDescriptorAction { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.IndexName> NamesValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.IndexPrivilege> PrivilegesValue { get; set; }
	private object? QueryValue { get; set; }

	/// <summary>
	/// <para>
	/// The document fields that the owners of the role have read access to.
	/// </para>
	/// </summary>
	public IndicesPrivilegesDescriptor FieldSecurity(Elastic.Clients.Elasticsearch.Serverless.Security.FieldSecurity? fieldSecurity)
	{
		FieldSecurityDescriptor = null;
		FieldSecurityDescriptorAction = null;
		FieldSecurityValue = fieldSecurity;
		return Self;
	}

	public IndicesPrivilegesDescriptor FieldSecurity(Elastic.Clients.Elasticsearch.Serverless.Security.FieldSecurityDescriptor descriptor)
	{
		FieldSecurityValue = null;
		FieldSecurityDescriptorAction = null;
		FieldSecurityDescriptor = descriptor;
		return Self;
	}

	public IndicesPrivilegesDescriptor FieldSecurity(Action<Elastic.Clients.Elasticsearch.Serverless.Security.FieldSecurityDescriptor> configure)
	{
		FieldSecurityValue = null;
		FieldSecurityDescriptor = null;
		FieldSecurityDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A list of indices (or index name patterns) to which the permissions in this entry apply.
	/// </para>
	/// </summary>
	public IndicesPrivilegesDescriptor Names(ICollection<Elastic.Clients.Elasticsearch.Serverless.IndexName> names)
	{
		NamesValue = names;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The index level privileges that owners of the role have on the specified indices.
	/// </para>
	/// </summary>
	public IndicesPrivilegesDescriptor Privileges(ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.IndexPrivilege> privileges)
	{
		PrivilegesValue = privileges;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A search query that defines the documents the owners of the role have access to. A document within the specified indices must match this query for it to be accessible by the owners of the role.
	/// </para>
	/// </summary>
	public IndicesPrivilegesDescriptor Query(object? query)
	{
		QueryValue = query;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (FieldSecurityDescriptor is not null)
		{
			writer.WritePropertyName("field_security");
			JsonSerializer.Serialize(writer, FieldSecurityDescriptor, options);
		}
		else if (FieldSecurityDescriptorAction is not null)
		{
			writer.WritePropertyName("field_security");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Security.FieldSecurityDescriptor(FieldSecurityDescriptorAction), options);
		}
		else if (FieldSecurityValue is not null)
		{
			writer.WritePropertyName("field_security");
			JsonSerializer.Serialize(writer, FieldSecurityValue, options);
		}

		writer.WritePropertyName("names");
		JsonSerializer.Serialize(writer, NamesValue, options);
		writer.WritePropertyName("privileges");
		JsonSerializer.Serialize(writer, PrivilegesValue, options);
		if (QueryValue is not null)
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, QueryValue, options);
		}

		writer.WriteEndObject();
	}
}